﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.IO;

namespace GeoVision.BingMap.Windows
{
    public partial class KeyInfoWindow : ChildWindow
    {
        public string BingKey { get; set; }
        public KeyInfoWindow()
        {
            InitializeComponent();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            MainPage.ApplicationId = txtKey.Text;
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            MainPage.ApplicationId = string.Empty;
            this.DialogResult = false;
        }

        public static void SaveData(string data, string fileName)
        {
            using (IsolatedStorageFile isolatedStoragFile = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(string.Format("{0}.txt", fileName), FileMode.Append, isolatedStoragFile))
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.Write(data);
                    }
                    stream.Close();
                }
            }
        }
        public static string LoadData(string fileName)
        {
            string s;
            using (IsolatedStorageFile isolatedStoragFile = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(string.Format("{0}.txt", fileName), FileMode.OpenOrCreate, isolatedStoragFile))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        s = reader.ReadLine();
                    }
                    stream.Close();
                }
            }
            return s;
        }
    }
}

